package ca.eloas.judging.rest.repositories;

import ca.eloas.judging.model.CompetitionObject;
import ca.eloas.judging.model.TeamObject;
import com.googlecode.objectify.Key;

import javax.inject.Singleton;

/**
 * @author JP
 */
@Singleton
public class OfyTeamRepository extends AbstractOfyRepository<TeamObject> implements TeamRepository {

    public OfyTeamRepository() {
        super(TeamObject.class);
    }


    public Iterable<TeamObject> getTeams(CompetitionObject competition) {

        return getPersistence().load().type(TeamObject.class).ancestor(competition).iterable();
    }

    public TeamObject getTeam(CompetitionObject competition, long id) {

        return getPersistence().load().key(Key.create(competition.getKey(), TeamObject.class, id)).get();
    }
}
